﻿Imports System.Data.SqlClient

Public Class adm_cn_productedit
    Inherits System.Web.UI.Page
    Private sSQL As String
    Private objrd As SqlDataReader = Nothing
    Private objfind As New GetData
    Private ps As New PreparedStatement(sSQL)

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Session("admin_ID") <> Nothing And Session("admin_ID") <> "") Then
            If (Request("uid") <> Nothing And Request("uid") <> "") Then
                Dim editType, productId, strErr As String
                editType = Request("editType")
                productId = Request("productId")
                strErr = ""
                If (editType = "delete") Then
                    ps.strSql = "update product_info set active='false', recommendation='false' where product_id=@productId"
                    ps.parameters.Clear()
                    ps.addParameter("productId", productId)
                    objfind.es(ps, strErr)
                    MsgBox("删除成功！")
                End If
                If (editType = "recommend") Then
                    ps.strSql = "update product_info set recommendation='true' where product_id=@productId"
                    ps.parameters.Clear()
                    ps.addParameter("productId", productId)
                    objfind.es(ps, strErr)
                    MsgBox("推荐成功！")
                End If
                If (editType = "cancelrecommend") Then
                    ps.strSql = "update product_info set recommendation='false' where product_id=@productId"
                    ps.parameters.Clear()
                    ps.addParameter("productId", productId)
                    objfind.es(ps, strErr)
                    MsgBox("推荐已取消！")
                End If
                If (editType = "active") Then
                    ps.strSql = "update product_info set active='true' where product_id=@productId"
                    ps.parameters.Clear()
                    ps.addParameter("productId", productId)
                    objfind.es(ps, strErr)
                    MsgBox("激活成功！")
                End If
                If (editType = "remove") Then
                    Dim dir As New IO.DirectoryInfo(Server.MapPath("../../") & "pic/product/" & productId)
                    If (dir.Exists) Then
                        For Each d As IO.FileInfo In dir.GetFiles
                            d.Delete()
                        Next
                        dir.Delete()
                    End If
                    ps.strSql = "delete from product_photo where product_id=@productId"
                    ps.parameters.Clear()
                    ps.addParameter("productId", productId)
                    objfind.es(ps, strErr)
                    ps.strSql = "delete from product_info where product_id=@productId"
                    ps.parameters.Clear()
                    ps.addParameter("productId", productId)
                    objfind.es(ps, strErr)
                    MsgBox("删除成功！")
                End If
                Response.Redirect("adm_cn_supplyManagement.aspx?uid=" & Request("uid"))
            Else
                Response.Redirect("../memberMngt_default.aspx")
            End If
        Else
            Response.Redirect("../adm_login.aspx")
        End If

    End Sub

End Class